Skip to content

perf: defer PostHog and Google Analytics init behind requestIdleCallback#254

Merged
brendanjryan merged 1 commit intomainfrom
brendan/defer-analytics-init
Apr 8, 2026
Merged

perf: defer PostHog and Google Analytics init behind requestIdleCallback#254
brendanjryan merged 1 commit intomainfrom
brendan/defer-analytics-init

Conversation

@decofe
Copy link
Copy Markdown
Member

@decofe decofe commented Apr 8, 2026

Wraps PostHog and Google Analytics initialization in requestIdleCallback (with setTimeout fallback for Safari) so analytics setup doesn't block the main thread during initial page load. Improves FCP/LCP.

Changes

  • src/components/PostHogSetup.tsx: wrap posthog.init + posthog.register in idle callback
  • src/components/GoogleAnalytics.tsx: wrap gtag setup + script injection in idle callback

Testing

pnpm run check:types passes.

Prompted by: Brendan

Co-authored-by: Brendan Ryan <1572504+brendanjryan@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d6e1a-2a8e-7257-a027-d6c2cb562b8b
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tempo-docs Ready Ready Preview, Comment Apr 8, 2026 5:33pm

Request Review

@brendanjryan brendanjryan merged commit 6f2dd08 into main Apr 8, 2026
9 checks passed
@brendanjryan brendanjryan deleted the brendan/defer-analytics-init branch April 8, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants